//
//  HomeBannerCell.m
//  jingdongfang
//
//  Created by LJL on 2018/5/7.
//  Copyright © 2018年 BOE. All rights reserved.
//

#import "HomeBannerCell.h"
#import "SDCycleScrollView.h"
#import "XiangQingViewController.h"
#import "IntroViewController.h"
#import "ZTXQViewController.h"
#import "GoodsDetailVC.h"
#import "BaseWebViewController.h"

@interface HomeBannerCell ()<SDCycleScrollViewDelegate>
{
    SDCycleScrollView *_cycleScrollView;
}

@end

@implementation HomeBannerCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setBackgroundColor:[UIColor clearColor]];
        
        CGRect frame = CGRectMake(0, 0, KSCREENWIDTH, BANNERHEIGHT);
        _cycleScrollView= [[SDCycleScrollView alloc] initWithFrame:frame];
        _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
        _cycleScrollView.delegate = self;
        _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        [self.contentView addSubview:_cycleScrollView];
    }
    return self;
}

- (void)setBannerArr:(NSMutableArray *)bannerArr {
    if (_bannerArr != bannerArr) {
        _bannerArr = bannerArr;
    }
    
    NSMutableArray *imgs = [NSMutableArray array];
    if (bannerArr.count > 0) {
        for (IGBanner *banner in bannerArr) {
            [imgs addObject:banner.image.length >0 ? banner.image : @""];
        }
    }
    _cycleScrollView.imageURLStringsGroup = imgs.count > 0 ? imgs : @[@""];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    IGBanner *banner = [self.bannerArr objectAtIndex:index];
    //1-作品 2-艺术家 3-专题 4-活动 5-商品 6-web页面
    NSString *linkType = banner.linkType;
    NSString *linkId = banner.linkId;
    if ([linkType isEqualToString:@"1"]) {
        XiangQingViewController *vc = [[XiangQingViewController alloc] init];
        vc.p_id = linkId;
        vc.isRoot = YES;
        [UIViewController ig_pushViewController:vc animated:YES];
    } else if ([linkType isEqualToString:@"2"]) {
        IntroViewController *vc = [[IntroViewController alloc] init];
        vc.u_id = linkId;
        [UIViewController ig_pushViewController:vc animated:YES];
    } else if ([linkType isEqualToString:@"3"] || [linkType isEqualToString:@"4"]) {
        ZTXQViewController *vc = [[ZTXQViewController alloc] init];
        vc.s_id = linkId;
        [UIViewController ig_pushViewController:vc animated:YES];
    } else if ([linkType isEqualToString:@"5"]) {
        GoodsDetailVC *vc = [[GoodsDetailVC alloc] init];
        vc.goodsId = linkId;
        [UIViewController ig_pushViewController:vc animated:YES];
    } else if ([linkType isEqualToString:@"6"]) {
        BaseWebViewController *vc = [[BaseWebViewController alloc] initWithUrl:linkId];
        [UIViewController ig_pushViewController:vc animated:YES];
    }
    
}
@end
